var assert = require('assert');
var should = require('should');
var util = require('util');
var zlib = require('zlib');
var _ = require('lodash');
var propertyHandler = require('../../../../app/servers/bag/handler/propertyHandler');
var bagModel = require('../../../../app/models/bagModel');
var config = require('../../../config');

suite('property', function () {
    setup(function (done) {
        bagModel.getByRoleId(config.role_id, function (err, bag_model) {
            bag_model.addProperty(3000101, 1);
            bag_model.save(done);
        });
    });

    test('出售道具', function (done) {
        var msg = {};

        var session = {};
        session.uid = config.role_id;

        var property_handler = new propertyHandler();
        property_handler.sell(msg, session, function (err, res) {
            res.code.should.equal(600);
            done();
        });
    });

    test('出售道具', function (done) {
        bagModel.getByRoleId(config.role_id, function (err, bag_model) {
            var property_id;
            var property_list = bag_model.getPropertyList();
            _.some(property_list, function (property_item) {
                if (property_item.property_id) {
                    property_id = property_item.property_id;
                    return;
                }
            });
            bag_model.save(function () {
                var msg = {
                    property_id: property_id
                };

                var session = {};
                session.uid = config.role_id;

                var property_handler = new propertyHandler();
                property_handler.sell(msg, session, function (err, res) {
                    done();
                });
            });
        });
    });
});
